/**
 * 
 */
package com.jm.utils.htmlNode;

import java.util.Hashtable;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

/**
 * @author yanjie
 * Oct 28, 2011 10:31:46 AM
 */
public class W3cNode extends BaseNode{
	protected Node node = null;
	@Override
	public void onInit(Object node) {
		super.onInit(node);
		this.node = (Node)node;
	}
	
	@Override
	public void loadConfig() {
		super.loadConfig();
		if(this.node != null){
			this.setNodeName(this.node.getNodeName());
			this.setNodeValue(this.node.getNodeValue());
			
			//處理屬性
			Hashtable attrsTab = new Hashtable();
			NamedNodeMap attrs = this.node.getAttributes();
			if (attrs != null)
			{
				for (int i = 0; i < attrs.getLength(); i++)
				{
					Node attrNode = attrs.item(i);
					if (attrNode != null)
						this.putAttribute(attrNode.getNodeName(), attrNode.getNodeValue());
				}
			}
			
			//處理子節點
			if(this.node.getChildNodes()!=null){
				NodeList nodeList = new NodeList();
				nodeList.fromNodeList(this.node.getChildNodes(),this.getPage());
				if(nodeList.size() > 0){
					this.setChildNodes(nodeList);
				}
			}
		}
	}
}
